package zzps.exeed.web.handle.argument;

import zzps.exeed.kernel.convert.Convert;
import zzps.exeed.kernel.holder.ParameterHolder;
import zzps.exeed.kernel.tool.ClassTool;
import zzps.exeed.web.Context;

public class SimpleTypeMethodArgumentResolver implements HandlerMethodArgumentResolver{
    @Override
    public boolean support(ParameterHolder parameterHolder) {
        boolean simpleType = ClassTool.isSimpleType(parameterHolder.getType());
        return simpleType;
    }

    @Override
    public Object resolveArgument(ParameterHolder parameterHolder, Context context) {
        String name = parameterHolder.getName();
        String parameter = context.getParameter(name);
        if (parameter != null){
            Object convert = Convert.convert(parameterHolder.getType(), parameter);
            return convert;
        }
        return null;
    }
}
